package com.example.controller;

import com.example.domain.ResponseCode;
import com.example.domain.ResponseResult;
import com.example.domain.User;
import com.example.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/login")
public class LoginController {

    private final LoginService loginService;

    // 请求体
    @PostMapping("/user")
    private ResponseResult login(@RequestBody User user) {
        // 登录
        Map<String, String> result = loginService.login(user);
        return new ResponseResult(
                result != null ? ResponseCode.LOGIN_SUCCESS : ResponseCode.LOGIN_ERROR,
                result != null ? "登录成功" : "登录失败",
                result
        );
    }

}
